<?php

/**
 * Description of AsyncController
 *
 * @author pdelavega
 */
class AsyncController extends Zend_Controller_Action
{

    //Call before call the action
    public function init()
    {
        //Disable Layout
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->getHelper('layout')->disableLayout();
        //Disable Layout
    }

    public function preDispatch()
    {
        $this->sesssion = new Zend_Session_Namespace('default');
        if (!$this->sesssion->view)
                $this->sesssion->view = $this->view;

        
    }

    public function getnoticeAction()
    {
        if ($this->getRequest()->getParam('clear'))
        {
            $this->sesssion->view = $this->view;
        }
        $text = $this->getRequest()->getParam('msg');
        echo $this->sesssion->view->notice($text);
    }


    public function getitemsAction()
    {
        echo Zend_Json_Encoder::encode($this->generateItems());
    }

    public function getitembyidAction()
    {
        $id = $this->getRequest()->getParam('itemId');
        $items = $this->generateItems();
        echo Zend_Json_Encoder::encode($items[$id]);
    }

    private function generateItems()
    {
        $item = array();

        for($i=0;$i < 5;$i++)
        {
            $newItem = new App_ItemDto(md5(uniqid()),'Desc of '.$i,$i);
            $item[] = $newItem;
        }
        return $item;
    }
}
?>
